<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="汽车品牌名称" prop="qichepinpai">
        <el-input
          v-model="queryParams.qichepinpai"
          placeholder="请输入汽车品牌名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型号" prop="chexinghao">
        <el-input
          v-model="queryParams.chexinghao"
          placeholder="请输入车型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经销商报价" prop="jingxiaoshangbaojia">
        <el-input
          v-model="queryParams.jingxiaoshangbaojia"
          placeholder="请输入经销商报价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排量" prop="pailiang">
        <el-input
          v-model="queryParams.pailiang"
          placeholder="请输入排量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="能源" prop="nengyuan">
        <el-input
          v-model="queryParams.nengyuan"
          placeholder="请输入能源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国别" prop="guobie">
        <el-input
          v-model="queryParams.guobie"
          placeholder="请输入国别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驱动" prop="qudong">
        <el-input
          v-model="queryParams.qudong"
          placeholder="请输入驱动"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="变速箱" prop="biansuxiang">
        <el-input
          v-model="queryParams.biansuxiang"
          placeholder="请输入变速箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结构" prop="jiegou">
        <el-input
          v-model="queryParams.jiegou"
          placeholder="请输入结构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车级别" prop="chrjibie">
        <el-input
          v-model="queryParams.chrjibie"
          placeholder="请输入车级别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称1" prop="chexingmingcheng1">
        <el-input
          v-model="queryParams.chexingmingcheng1"
          placeholder="请输入车型名称1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="厂家指导价1" prop="changjiazhidaojia1">
        <el-input
          v-model="queryParams.changjiazhidaojia1"
          placeholder="请输入厂家指导价1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="环保标准" prop="huanbaobiaozhun">
        <el-input
          v-model="queryParams.huanbaobiaozhun"
          placeholder="请输入环保标准"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最大功率(kW)" prop="zuidagonglv">
        <el-input
          v-model="queryParams.zuidagonglv"
          placeholder="请输入最大功率(kW)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="长*宽*高" prop="changkuangao">
        <el-input
          v-model="queryParams.changkuangao"
          placeholder="请输入长*宽*高"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最高车速(km/h)" prop="zuigaochesu">
        <el-input
          v-model="queryParams.zuigaochesu"
          placeholder="请输入最高车速(km/h)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称2" prop="chexingmingcheng2">
        <el-input
          v-model="queryParams.chexingmingcheng2"
          placeholder="请输入车型名称2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="厂家指导价2" prop="changjiazhidaojia2">
        <el-input
          v-model="queryParams.changjiazhidaojia2"
          placeholder="请输入厂家指导价2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称3" prop="chexingmingcheng3">
        <el-input
          v-model="queryParams.chexingmingcheng3"
          placeholder="请输入车型名称3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="厂家指导价3" prop="changjiazhidaojia3">
        <el-input
          v-model="queryParams.changjiazhidaojia3"
          placeholder="请输入厂家指导价3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除 默认未删除 " prop="isDeleted">
        <el-input
          v-model="queryParams.isDeleted"
          placeholder="请输入是否删除 默认未删除 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label=" " align="center" prop="id" />
      <el-table-column label="汽车品牌名称" align="center" prop="qichepinpai" />
      <el-table-column label="车型号" align="center" prop="chexinghao" />
      <el-table-column label="经销商报价" align="center" prop="jingxiaoshangbaojia" />
      <el-table-column label="排量" align="center" prop="pailiang" />
      <el-table-column label="能源" align="center" prop="nengyuan" />
      <el-table-column label="国别" align="center" prop="guobie" />
      <el-table-column label="驱动" align="center" prop="qudong" />
      <el-table-column label="变速箱" align="center" prop="biansuxiang" />
      <el-table-column label="结构" align="center" prop="jiegou" />
      <el-table-column label="车级别" align="center" prop="chrjibie" />
      <el-table-column label="车型名称1" align="center" prop="chexingmingcheng1" />
      <el-table-column label="厂家指导价1" align="center" prop="changjiazhidaojia1" />
      <el-table-column label="环保标准" align="center" prop="huanbaobiaozhun" />
      <el-table-column label="最大功率(kW)" align="center" prop="zuidagonglv" />
      <el-table-column label="长*宽*高" align="center" prop="changkuangao" />
      <el-table-column label="最高车速(km/h)" align="center" prop="zuigaochesu" />
      <el-table-column label="车型名称2" align="center" prop="chexingmingcheng2" />
      <el-table-column label="厂家指导价2" align="center" prop="changjiazhidaojia2" />
      <el-table-column label="车型名称3" align="center" prop="chexingmingcheng3" />
      <el-table-column label="厂家指导价3" align="center" prop="changjiazhidaojia3" />
      <el-table-column label="是否删除 默认未删除 " align="center" prop="isDeleted" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="汽车品牌名称" prop="qichepinpai">
          <el-input v-model="form.qichepinpai" placeholder="请输入汽车品牌名称" />
        </el-form-item>
        <el-form-item label="车型号" prop="chexinghao">
          <el-input v-model="form.chexinghao" placeholder="请输入车型号" />
        </el-form-item>
        <el-form-item label="经销商报价" prop="jingxiaoshangbaojia">
          <el-input v-model="form.jingxiaoshangbaojia" placeholder="请输入经销商报价" />
        </el-form-item>
        <el-form-item label="排量" prop="pailiang">
          <el-input v-model="form.pailiang" placeholder="请输入排量" />
        </el-form-item>
        <el-form-item label="能源" prop="nengyuan">
          <el-input v-model="form.nengyuan" placeholder="请输入能源" />
        </el-form-item>
        <el-form-item label="国别" prop="guobie">
          <el-input v-model="form.guobie" placeholder="请输入国别" />
        </el-form-item>
        <el-form-item label="驱动" prop="qudong">
          <el-input v-model="form.qudong" placeholder="请输入驱动" />
        </el-form-item>
        <el-form-item label="变速箱" prop="biansuxiang">
          <el-input v-model="form.biansuxiang" placeholder="请输入变速箱" />
        </el-form-item>
        <el-form-item label="结构" prop="jiegou">
          <el-input v-model="form.jiegou" placeholder="请输入结构" />
        </el-form-item>
        <el-form-item label="车级别" prop="chrjibie">
          <el-input v-model="form.chrjibie" placeholder="请输入车级别" />
        </el-form-item>
        <el-form-item label="车型名称1" prop="chexingmingcheng1">
          <el-input v-model="form.chexingmingcheng1" placeholder="请输入车型名称1" />
        </el-form-item>
        <el-form-item label="厂家指导价1" prop="changjiazhidaojia1">
          <el-input v-model="form.changjiazhidaojia1" placeholder="请输入厂家指导价1" />
        </el-form-item>
        <el-form-item label="环保标准" prop="huanbaobiaozhun">
          <el-input v-model="form.huanbaobiaozhun" placeholder="请输入环保标准" />
        </el-form-item>
        <el-form-item label="最大功率(kW)" prop="zuidagonglv">
          <el-input v-model="form.zuidagonglv" placeholder="请输入最大功率(kW)" />
        </el-form-item>
        <el-form-item label="长*宽*高" prop="changkuangao">
          <el-input v-model="form.changkuangao" placeholder="请输入长*宽*高" />
        </el-form-item>
        <el-form-item label="最高车速(km/h)" prop="zuigaochesu">
          <el-input v-model="form.zuigaochesu" placeholder="请输入最高车速(km/h)" />
        </el-form-item>
        <el-form-item label="车型名称2" prop="chexingmingcheng2">
          <el-input v-model="form.chexingmingcheng2" placeholder="请输入车型名称2" />
        </el-form-item>
        <el-form-item label="厂家指导价2" prop="changjiazhidaojia2">
          <el-input v-model="form.changjiazhidaojia2" placeholder="请输入厂家指导价2" />
        </el-form-item>
        <el-form-item label="车型名称3" prop="chexingmingcheng3">
          <el-input v-model="form.chexingmingcheng3" placeholder="请输入车型名称3" />
        </el-form-item>
        <el-form-item label="厂家指导价3" prop="changjiazhidaojia3">
          <el-input v-model="form.changjiazhidaojia3" placeholder="请输入厂家指导价3" />
        </el-form-item>
        <el-form-item label="是否删除 默认未删除 " prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入是否删除 默认未删除 " />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/carInfo";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        qichepinpai: null,
        chexinghao: null,
        jingxiaoshangbaojia: null,
        pailiang: null,
        nengyuan: null,
        guobie: null,
        qudong: null,
        biansuxiang: null,
        jiegou: null,
        chrjibie: null,
        chexingmingcheng1: null,
        changjiazhidaojia1: null,
        huanbaobiaozhun: null,
        zuidagonglv: null,
        changkuangao: null,
        zuigaochesu: null,
        chexingmingcheng2: null,
        changjiazhidaojia2: null,
        chexingmingcheng3: null,
        changjiazhidaojia3: null,
        isDeleted: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        qichepinpai: null,
        chexinghao: null,
        jingxiaoshangbaojia: null,
        pailiang: null,
        nengyuan: null,
        guobie: null,
        qudong: null,
        biansuxiang: null,
        jiegou: null,
        chrjibie: null,
        chexingmingcheng1: null,
        changjiazhidaojia1: null,
        huanbaobiaozhun: null,
        zuidagonglv: null,
        changkuangao: null,
        zuigaochesu: null,
        chexingmingcheng2: null,
        changjiazhidaojia2: null,
        chexingmingcheng3: null,
        changjiazhidaojia3: null,
        isDeleted: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
